﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

using Sky.Web.Models;

namespace Sky.Web.Controllers
{
    public class StoreController : Controller
    {
        StoreEntities storeDB = new StoreEntities();
        //
        // GET: /Store/

        //public ActionResult Index()
        //{
        //    return View();
        //}
        public ActionResult Index()
        {
            var genres = storeDB.Genres.ToList(); 
            return this.View(genres);
        }

        public ActionResult Browse(string genre) 
        {
            // /Store/Browse?genre=DISCO
            var genreModel = storeDB.Genres.Include("ALbums").Single(g => g.Name == genre); 
            //var genreModel = new Genre { Name = genre };
            return this.View(genreModel);
        }

        public ActionResult Detail(int id)
        {
            // /Store/Detail/5
            var album = storeDB.Albums.Find(id);
            //string message = "Store.Details, ID = " + id; 
            return View(album);
        }

        //这意味着我们仅仅可以通过分部视图来访问这个 Action，这可以防止通过浏览 /Store/GenreMenu 来访问
        [ChildActionOnly]
        public ActionResult GenreMenu()
        {
            var genre = storeDB.Genres.ToList();
            return PartialView(genre);
        }
    }
}
